package com.example.zbh.dsliao.view;

import android.app.Dialog;
import android.content.Context;
import android.content.res.Resources;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import com.example.zbh.dsliao.R;
import com.example.zbh.dsliao.ui.activty.TransmitActivity;

/**
 * 自定义选择dialog
 */
public class CustomChangeDialog extends Dialog implements View.OnClickListener {

    private static int default_width = 500;//默认宽度
    private static int default_height = 500;//默认高度
    private Button changeOneBtn, changeTwoBtn, cancleBtn;
    private TextView titleMessage;
    private String oneBtnTv, twoBtnTv, threeBtnTv;
    private Context context;
    private int alpha;
    private String title;

    private CustomChangeDialogListener customChangeDialogListener;



    public void setCustomChangeDialogListener(CustomChangeDialogListener customChangeDialogListener){
        this.customChangeDialogListener = customChangeDialogListener;
    }

    public interface CustomChangeDialogListener{
        void onClick(View view);
    }


    public CustomChangeDialog(Context context,String title,int alpha, String oneBtn, String twoBtn, String ThreeBtn) {
            super(context, R.style.ChangeDialogTheme);
        this.context = context;
        this.oneBtnTv = oneBtn;
        this.twoBtnTv = twoBtn;
        this.alpha = alpha;
        this.title = title;
        this.threeBtnTv = ThreeBtn;
        init();

    }

    private void init(){
        setContentView(R.layout.changedialog_layout);
        titleMessage = (TextView)findViewById(R.id.titleMessage);
        titleMessage.setText(title);
        changeOneBtn = (Button)findViewById(R.id.changeOneBtn);
        changeOneBtn.getBackground().setAlpha(100);
        changeOneBtn.setVisibility(alpha);
        changeTwoBtn = (Button)findViewById(R.id.changeTwoBtn);
        changeTwoBtn.getBackground().setAlpha(100);
        cancleBtn = (Button)findViewById(R.id.cancleBtn);
        cancleBtn.getBackground().setAlpha(100);
        changeOneBtn.setText(oneBtnTv);
        changeTwoBtn.setText(twoBtnTv);
        cancleBtn.setText(threeBtnTv);

        changeOneBtn.setOnClickListener(this);
        changeTwoBtn.setOnClickListener(this);
        cancleBtn.setOnClickListener(this);


        Window window = getWindow();
        WindowManager.LayoutParams params = window.getAttributes();
        float density = getDensity(context);
        params.width = default_width;
        params.height = default_height;
        window.setAttributes(params);

    }

    /**
     * 获取显示密度
     * **/
    public float getDensity(Context context) {
        Resources resources = context.getResources();
        DisplayMetrics dm = resources.getDisplayMetrics();
        return dm.density;
    }


    @Override
    public void onClick(View v) {

        customChangeDialogListener.onClick(v);
    }



}
